# -*- coding: utf-8 -*-
from Tkinter import *
import tkFileDialog
import tkMessageBox as msgBox
import sys
from RequeteSQL import *
RequeteSQL = RequeteSQL()
import xmlrpclib
class VueSaisieChamps(Frame):
    def __init__(self,master,parent,**cnf):
        self.ListeChamps=[]
        KeysList=cnf.keys()
        self.parent = parent
        self.master=master
        self.width=400
        self.height=200
        if ('width' in KeysList):
            self.width=cnf['width']
        if ('width' in KeysList):
            self.height=cnf['height']
        Frame.__init__(self,master,cnf)             
        self.pack(side=LEFT,anchor=NW)
        self.config(bg='#046380')
        
        
        #Reponse = self.parent.serveur.ExecuterRequeteSQLWhere(RequeteSQL.sqlColumn('PERP_CONTRAINTES'))
        #if (Reponse[0]==1):
         #   ListeChamps = Reponse[1]
        #else:
          #  msgBox.showerror('PERP 2009 | dition des tables', 'Une erreur est survenue!\n'+Reponse[1])
       
        
        #self.listeLabel=["Erna","Mohamed","Jamal","Daniel","Mounia","Mathieu"]
        #self.listeChamp=["champ1","champ2","champ3","champ4","champ5","champ6"]
        
        #appel � la methode poru cr�er le nombre de champ pour la saisie des donn�es
        self.obtenirChamps()
        
        #self.placerLabel(self.listeLabel)
        #self.placerChamp(self.listeChamp)
       # self.obtenirChamps()
      

    #def placerLabel(self,listeLabel):
     #   column=0
    #    for i in range(len(listeLabel)):
   #        text=Label(self,text=self.listeLabel[i], width=10,bg='#6B979C').grid(column=column, row = 0)
      #      column=column+1
    
   # def placerChamp(self,listeChamp):
      #  column=0
     #   for i in range(len(listeChamp)):
     #       Entree=Entry(self, textvariable=self.listeChamp[i],width=11,bg='#F7F2B2')
     #       Entree.grid(column=column, row = i + 1)
        #    column=column+1
   
     #cette methode permet � l'usager de pourvoir faire la saisie des elements d'une table           
    def obtenirChamps(self):
        column=0 
       
        Reponse = self.parent.serveur.ExecuterRequeteSQLWhere(RequeteSQL.sqlColumn('PERP_CONTRAINTES'))
        if(Reponse[0]==1):
            self.ListeChamps = Reponse[1]
            for i in range(len(self.ListeChamps)):
                text=Label(self,text=self.ListeChamps[i], width=10,bg='#6B979C').grid(column=column, row = 0)
                column=column+1
         
            column=0   
            for i in range(len(self.ListeChamps)):
                Entree=Entry(self, textvariable=self.ListeChamps[i],width=11,bg='#F7F2B2').grid(column=column, row = 1)
                column=column+1
         
            
        #print ListeChamps
        else:
          msgBox.showerror('PERP 2009 | dition des tables', 'Une erreur est survenue!\n'+Reponse[1])
        #pass
        

    def close(self):
        self.destroy()
        pass

    def repaint(self,evt):
        self.master.update()
        self.x=self.master.winfo_width()/2-(self.width/2)
        self.y=self.master.winfo_height()/2-(self.height/2)       
        self.place(x=self.x,y=self.y)
        pass
##-------------------------------------------------------------------------------------------------------------------------
#    
#    def obtenirChamps(self):         
#        Reponse = self.parent.serveur.ExecuterRequeteSQL(ExecuterRequeteSQL(self.CBListeTables.getText()))      
#        if (Reponse[0]==1):             
#            ListeChamps = Reponse[1]             
#            self.LesChamps = ListeChamps             
#            self.CBListeChamps.clear()             
#            self.CBListeChamps.setListHeight(3)             
#            for UnChamp in ListeChamps:                         
#                self.CBListeChamps.addItem(UnChamp.Nom)             
#            self.CBListeChamps.setSelected(0)             
#            self.CBListeChamps.setText('<CHOISIR>') 
#            print len(ListeChamps)
#            
#        else:             
#            msgBox.showerror('PERP 2009 | edition des tables', 'Une erreur est survenue!\n'+Reponse[1])
#            pass 
#        
#        print len(ListeChamps)
#    
    

#---------------------------------------------------------------------------------------------------------------------------------
        
if __name__ == '__main__':
    Serveur='http://localhost:8000'
    serveur=xmlrpclib.ServerProxy(Serveur)
    root=Tk()
    root.geometry('600x400')
    vi=VueSaisieChamps(root,None)
    root.mainloop()       
        
        
    

            



    
    
    
